import fileDownload from "js-file-download";
import Qs from "qs"

export const getConfig = {
  headers: {
    "X-Requested-With": "XMLHttpRequest",
  },
  paramsSerializer(params) {
    return Qs.stringify(params, {
      arrayFormat: "brackets",
    });
  },
  timeout: 5000,
};

export const postConfig = {
  headers: {
    "Content-Type": "application/json",
    "X-Requested-With": "XMLHttpRequest",
  },
  transformRequest: [
    function (data) {
      return JSON.stringify(data.params || {});
    },
  ],
  timeout: 5000,
  responseType: "json",
};


export const downloadConfig = {
  headers: {
    "Content-Type": "application/json",
    "X-Requested-With": "XMLHttpRequest",
  },
  transformResponse: [
    function (data) {
      if (JSON.stringify(data) === "{}") {
        fileDownload(data, "文件");
      }
      return data;
    },
  ],
  timeout: 20000,
  responseType: "blob",
};

export const formConfig = {
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
    "X-Requested-With": "XMLHttpRequest",
  },
  timeout: 20000,
};
